/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import fse from 'fs-extra';
import path from 'path';
import { ProjectStructureOpt } from '../../../../src/base/common/options/project-structure-opt';
import { Json5Reader } from '../../../../src/base/util/json5-reader';

export function writeFileContent(filePath: string, content: string) {
  if (!fse.existsSync(filePath)) {
    return;
  }
  fse.writeFileSync(filePath, content);
}

export function addModule(projectRootPath: string, moduleName: string) {
  const buildProfilePath = path.resolve(projectRootPath, 'build-profile.json5');
  const projectStructureOpt: ProjectStructureOpt = Json5Reader.getJson5Obj(buildProfilePath);
  const modules = projectStructureOpt.modules;
  modules.push({
    name:moduleName,
    srcPath: `./${moduleName}`
  });
  writeFileContent(buildProfilePath, JSON.stringify(projectStructureOpt));
}
